<template>
  <div>
    <basic-container>
      <avue-crud
        :option="tableOption"
        :data="tableData"
        :table-loading="tableLoading"
        :page="page"
        ref="crud"
        @refresh-change="handleRefreshChange"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        @selection-change="handleSelectionChange"
        @search-change="handleSearchChange"
      >
        <template slot="menuLeft"></template>
        <template slot="Link" scope="scope">
          <div
            class="downlink"
            v-if="scope.row.Link"
            @click="handleDownloadLink(scope.row)"
          >{{scope.row.Link}}</div>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>
  <script>
import { validatenull } from "@/util/validate";
import { getLabelFromDic } from "@/const/dic";
// import { DIC } from "@/const/dic";
import { nowDate } from "../../util/date";
import * as apiObj from "@/api/exportTask";
import { exportTaskTableOption } from "@/const/exportTask/exportTaskTableOption.js";

export default {
  data() {
    return {
      bachDeleting: false,
      tableOption: {}, //表格设置属性
      tableData: [], //表格的数据
      tablePage: 1,
      downloadLoading: false,
      tableLoading: false,
      tableQueryParam: {},
      page: {
        total: 0, //总页数
        currentPage: 1, //当前页数
        pageSize: 10 //每页显示多少条
      }
    };
  },
  created() {
    //初始化数据格式
    this.tableOption = exportTaskTableOption;
    this.handleList();
  },
  methods: {
    handleCurrentChange(page) {
      this.page.currentPage = page;
      this.handleList();
    },
    handleDownloadLink(row) {
      if (row.Link) {
        this.openWin(row.Link);
      }
    },
    handleSizeChange(size) {
      this.page.pageSize = size;
      this.handleList();
    },

    handleSelectionChange(args) {
      this.currentSelectedRowIds = args.map(el => el.Id);
    },
    handleSearchChange(params) {
      this.tableQueryParam = params;
      this.handleList();
    },

    handleRefreshChange() {
      this.handleList();
    },
    /**
     * @title 获取数据
     * @detail 赋值为tableData表格即可
     *
     **/
    handleList() {
      this.tableLoading = true;
      apiObj
        .list({
          pageNo: this.page.currentPage,
          pageSize: this.page.pageSize,
          ...this.tableQueryParam
        })
        .then(data => {
          this.tableData = data.rows || [];
          this.page.total = data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    }
  }
};
</script>
<style scoped>
.downlink {
  color: blue;
  cursor: pointer;
  text-decoration: underline;
}
</style>
